﻿using System;
using NUnit.Framework;

namespace CodeContrib.Tests
{
	public class ExpressionEvaluatorTests
	{
		[Test]
		public void Evaluate_With_Addition()
		{
			// Arrange
			const string expression = "1 + 1";

			const int expected = 2;

			var expressionEvaluator = new ExpressionEvaluator();

			// Act
			var actual = (int)expressionEvaluator.Evaluate(expression);

			// Assert
			Assert.AreEqual(expected, actual);
		}

		[Test]
		public void Evaluate_With_Conditional_Statement_ShouldReturn_False()
		{
			// Arrange
			const string expression = "1 == 2";

			const bool expected = false;

			var expressionEvaluator = new ExpressionEvaluator();

			// Act
			var actual = (bool)expressionEvaluator.Evaluate(expression);

			// Assert
			Assert.AreEqual(expected, actual);
		}

		[Test]
		public void Evaluate_With_Conditional_Statement_ShouldReturn_True()
		{
			// Arrange
			const string expression = "1 == 1";

			const bool expected = true;

			var expressionEvaluator = new ExpressionEvaluator();

			// Act
			var actual = (bool)expressionEvaluator.Evaluate(expression);

			// Assert
			Assert.AreEqual(expected, actual);
		}

		[Test]
		[ExpectedException(typeof (ApplicationException))]
		public void Evaluate_With_Divide_By_Zero_ShouldThrow_ApplicationException()
		{
			// Arrange
			const string expression = "1 / 0";

			var expressionEvaluator = new ExpressionEvaluator();

			// Act
			expressionEvaluator.Evaluate(expression);
		}
	}
}